<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopGoodsCommentTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_goods_comment', ['comment' => '商品评价', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('goods_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '商品'])
            ->addColumn('order_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '订单'])
            ->addColumn('order_item_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '订单商品'])
            ->addColumn('user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn(Column::enum('user_type', ['user', 'fake_user'])->setDefault('user')->setComment('用户类型:user=用户,fake_user=虚拟用户'))
            ->addColumn('user_nickname', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '用户昵称'])
            ->addColumn('user_avatar', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '用户头像'])
            ->addColumn(Column::tinyInteger('level')->setDefault(0)->setUnsigned()->setComment('评价星级'))
            ->addColumn('content', 'string', ['limit' => 512, 'null' => true, 'default' => null, 'comment' => '评价内容'])
            ->addColumn('images', 'string', ['limit' => 2500, 'null' => true, 'default' => null, 'comment' => '评价图片'])
            ->addColumn(Column::enum('status', ['normal', 'hidden'])->setDefault('normal')->setComment('显示状态:normal=正常,hidden=隐藏'))
            ->addColumn('admin_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '管理员'])
            ->addColumn('reply_content', 'string', ['limit' => 512, 'null' => true, 'default' => null, 'comment' => '回复内容'])
            ->addColumn('reply_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '回复时间'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addColumn('delete_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '删除时间'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_goods_comment');
        $table->drop();
    }
}
